home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb-4.5 / sun4.md / gdb / infrun.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-15  |  58.0 KB  |  1,964 lines

  1. /* Start (run) and stop the inferior process, for GDB.
  2.    Copyright 1986, 1987, 1988, 1989, 1991, 1992 Free Software Foundation, Inc.
  3.  
  4. This file is part of GDB.
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /* Notes on the algorithm used in wait_for_inferior to determine if we
  21.    just did a subroutine call when stepping.  We have the following
  22.    information at that point:
  23.  
  24.                   Current and previous (just before this step) pc.
  25.           Current and previous sp.
  26.           Current and previous start of current function.
  27.  
  28.    If the starts of the functions don't match, then
  29.  
  30.        a) We did a subroutine call.
  31.  
  32.    In this case, the pc will be at the beginning of a function.
  33.  
  34.     b) We did a subroutine return.
  35.  
  36.    Otherwise.
  37.  
  38.     c) We did a longjmp.
  39.  
  40.    If we did a longjump, we were doing "nexti", since a next would
  41.    have attempted to skip over the assembly language routine in which
  42.    the longjmp is coded and would have simply been the equivalent of a
  43.    continue.  I consider this ok behaivior.  We'd like one of two
  44.    things to happen if we are doing a nexti through the longjmp()
  45.    routine: 1) It behaves as a stepi, or 2) It acts like a continue as
  46.    above.  Given that this is a special case, and that anybody who
  47.    thinks that the concept of sub calls is meaningful in the context
  48.    of a longjmp, I'll take either one.  Let's see what happens.  
  49.  
  50.    Acts like a subroutine return.  I can handle that with no problem
  51.    at all.
  52.  
  53.    -->So: If the current and previous beginnings of the current
  54.    function don't match, *and* the pc is at the start of a function,
  55.    we've done a subroutine call.  If the pc is not at the start of a
  56.    function, we *didn't* do a subroutine call.  
  57.  
  58.    -->If the beginnings of the current and previous function do match,
  59.    either: 
  60.  
  61.        a) We just did a recursive call.
  62.  
  63.        In this case, we would be at the very beginning of a
  64.        function and 1) it will have a prologue (don't jump to
  65.        before prologue, or 2) (we assume here that it doesn't have
  66.        a prologue) there will have been a change in the stack
  67.        pointer over the last instruction.  (Ie. it's got to put
  68.        the saved pc somewhere.  The stack is the usual place.  In
  69.        a recursive call a register is only an option if there's a
  70.        prologue to do something with it.  This is even true on
  71.        register window machines; the prologue sets up the new
  72.        window.  It might not be true on a register window machine
  73.        where the call instruction moved the register window
  74.        itself.  Hmmm.  One would hope that the stack pointer would
  75.        also change.  If it doesn't, somebody send me a note, and
  76.        I'll work out a more general theory.
  77.        bug-gdb@prep.ai.mit.edu).  This is true (albeit slipperly
  78.        so) on all machines I'm aware of:
  79.  
  80.           m68k:    Call changes stack pointer.  Regular jumps don't.
  81.  
  82.           sparc:    Recursive calls must have frames and therefor,
  83.                     prologues.
  84.  
  85.           vax:    All calls have frames and hence change the
  86.                     stack pointer.
  87.  
  88.     b) We did a return from a recursive call.  I don't see that we
  89.        have either the ability or the need to distinguish this
  90.        from an ordinary jump.  The stack frame will be printed
  91.        when and if the frame pointer changes; if we are in a
  92.        function without a frame pointer, it's the users own
  93.        lookout.
  94.  
  95.     c) We did a jump within a function.  We assume that this is
  96.        true if we didn't do a recursive call.
  97.  
  98.     d) We are in no-man's land ("I see no symbols here").  We
  99.        don't worry about this; it will make calls look like simple
  100.        jumps (and the stack frames will be printed when the frame
  101.        pointer moves), which is a reasonably non-violent response.
  102. */
  103.  
  104. #include "defs.h"
  105. #include <string.h>
  106. #include "symtab.h"
  107. #include "frame.h"
  108. #include "inferior.h"
  109. #include "breakpoint.h"
  110. #include "wait.h"
  111. #include "gdbcore.h"
  112. #include "signame.h"
  113. #include "command.h"
  114. #include "terminal.h"        /* For #ifdef TIOCGPGRP and new_tty */
  115. #include "target.h"
  116.  
  117. #include <signal.h>
  118.  
  119. /* unistd.h is needed to #define X_OK */
  120. #ifdef USG
  121. #include <unistd.h>
  122. #else
  123. #include <sys/file.h>
  124. #endif
  125.  
  126. #ifdef SET_STACK_LIMIT_HUGE
  127. #include <sys/time.h>
  128. #include <sys/resource.h>
  129.  
  130. extern int remote_debugging;
  131. extern int original_stack_limit;
  132. #endif /* SET_STACK_LIMIT_HUGE */
  133.  
  134. /* Prototypes for local functions */
  135.  
  136. static void
  137. signals_info PARAMS ((char *, int));
  138.  
  139. static void
  140. handle_command PARAMS ((char *, int));
  141.  
  142. static void
  143. sig_print_info PARAMS ((int));
  144.  
  145. static void
  146. sig_print_header PARAMS ((void));
  147.  
  148. static void
  149. remove_step_breakpoint PARAMS ((void));
  150.  
  151. static void
  152. insert_step_breakpoint PARAMS ((void));
  153.  
  154. static void
  155. resume PARAMS ((int, int));
  156.  
  157. static void
  158. resume_cleanups PARAMS ((int));
  159.  
  160. extern char **environ;
  161.  
  162. extern int sys_nerr;
  163. extern char *sys_errlist[];
  164.  
  165. extern struct target_ops child_ops;    /* In inftarg.c */
  166.  
  167. /* Sigtramp is a routine that the kernel calls (which then calls the
  168.    signal handler).  On most machines it is a library routine that
  169.    is linked into the executable.
  170.  
  171.    This macro, given a program counter value and the name of the
  172.    function in which that PC resides (which can be null if the
  173.    name is not known), returns nonzero if the PC and name show
  174.    that we are in sigtramp.
  175.  
  176.    On most machines just see if the name is sigtramp (and if we have
  177.    no name, assume we are not in sigtramp).  */
  178. #if !defined (IN_SIGTRAMP)
  179. #define IN_SIGTRAMP(pc, name) \
  180.   (name && !strcmp ("_sigtramp", name))
  181. #endif
  182.  
  183. /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the
  184.    program.  It needs to examine the jmp_buf argument and extract the PC
  185.    from it.  The return value is non-zero on success, zero otherwise. */
  186. #ifndef GET_LONGJMP_TARGET
  187. #define GET_LONGJMP_TARGET(PC_ADDR) 0
  188. #endif
  189.  
  190.  
  191. /* Some machines have trampoline code that sits between function callers
  192.    and the actual functions themselves.  If this machine doesn't have
  193.    such things, disable their processing.  */
  194. #ifndef SKIP_TRAMPOLINE_CODE
  195. #define    SKIP_TRAMPOLINE_CODE(pc)    0
  196. #endif
  197.  
  198. /* For SVR4 shared libraries, each call goes through a small piece of
  199.    trampoline code in the ".init" section.  IN_SOLIB_TRAMPOLINE evaluates
  200.    to nonzero if we are current stopped in one of these. */
  201. #ifndef IN_SOLIB_TRAMPOLINE
  202. #define IN_SOLIB_TRAMPOLINE(pc,name)    0
  203. #endif
  204.  
  205. /* Notify other parts of gdb that might care that signal handling may
  206.    have changed for one or more signals. */
  207. #ifndef NOTICE_SIGNAL_HANDLING_CHANGE
  208. #define NOTICE_SIGNAL_HANDLING_CHANGE    /* No actions */
  209. #endif
  210.  
  211. #ifdef TDESC
  212. #include "tdesc.h"
  213. int safe_to_init_tdesc_context = 0;
  214. extern dc_dcontext_t current_context;
  215. #endif
  216.  
  217. /* Tables of how to react to signals; the user sets them.  */
  218.  
  219. static char signal_stop[NSIG];
  220. static char signal_print[NSIG];
  221. static char signal_program[NSIG];
  222.  
  223. /* Nonzero if breakpoints are now inserted in the inferior.  */
  224. /* Nonstatic for initialization during xxx_create_inferior. FIXME. */
  225.  
  226. /*static*/ int breakpoints_inserted;
  227.  
  228. /* Function inferior was in as of last step command.  */
  229.  
  230. static struct symbol *step_start_function;
  231.  
  232. /* Nonzero => address for special breakpoint for resuming stepping.  */
  233.  
  234. static CORE_ADDR step_resume_break_address;
  235.  
  236. /* Pointer to orig contents of the byte where the special breakpoint is.  */
  237.  
  238. static char step_resume_break_shadow[BREAKPOINT_MAX];
  239.  
  240. /* Nonzero means the special breakpoint is a duplicate
  241.    so it has not itself been inserted.  */
  242.  
  243. static int step_resume_break_duplicate;
  244.  
  245. /* Nonzero if we are expecting a trace trap and should proceed from it.  */
  246.  
  247. static int trap_expected;
  248.  
  249. /* Nonzero if the next time we try to continue the inferior, it will
  250.    step one instruction and generate a spurious trace trap.
  251.    This is used to compensate for a bug in HP-UX.  */
  252.  
  253. static int trap_expected_after_continue;
  254.  
  255. /* Nonzero means expecting a trace trap
  256.    and should stop the inferior and return silently when it happens.  */
  257.  
  258. int stop_after_trap;
  259.  
  260. /* Nonzero means expecting a trap and caller will handle it themselves.
  261.    It is used after attach, due to attaching to a process;
  262.    when running in the shell before the child program has been exec'd;
  263.    and when running some kinds of remote stuff (FIXME?).  */
  264.  
  265. int stop_soon_quietly;
  266.  
  267. /* Nonzero if pc has been changed by the debugger
  268.    since the inferior stopped.  */
  269.  
  270. int pc_changed;
  271.  
  272. /* Nonzero if proceed is being used for a "finish" command or a similar
  273.    situation when stop_registers should be saved.  */
  274.  
  275. int proceed_to_finish;
  276.  
  277. /* Save register contents here when about to pop a stack dummy frame,
  278.    if-and-only-if proceed_to_finish is set.
  279.    Thus this contains the return value from the called function (assuming
  280.    values are returned in a register).  */
  281.  
  282. char stop_registers[REGISTER_BYTES];
  283.  
  284. /* Nonzero if program stopped due to error trying to insert breakpoints.  */
  285.  
  286. static int breakpoints_failed;
  287.  
  288. /* Nonzero after stop if current stack frame should be printed.  */
  289.  
  290. static int stop_print_frame;
  291.  
  292. #ifdef NO_SINGLE_STEP
  293. extern int one_stepped;        /* From machine dependent code */
  294. extern void single_step ();    /* Same. */
  295. #endif /* NO_SINGLE_STEP */
  296.  
  297.  
  298. /* Things to clean up if we QUIT out of resume ().  */
  299. /* ARGSUSED */
  300. static void
  301. resume_cleanups (arg)
  302.      int arg;
  303. {
  304.   normal_stop ();
  305. }
  306.  
  307. /* Resume the inferior, but allow a QUIT.  This is useful if the user
  308.    wants to interrupt some lengthy single-stepping operation
  309.    (for child processes, the SIGINT goes to the inferior, and so
  310.    we get a SIGINT random_signal, but for remote debugging and perhaps
  311.    other targets, that's not true).
  312.  
  313.    STEP nonzero if we should step (zero to continue instead).
  314.    SIG is the signal to give the inferior (zero for none).  */
  315. static void
  316. resume (step, sig)
  317.      int step;
  318.      int sig;
  319. {
  320. /*  struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);*/
  321.   QUIT;
  322.  
  323.   if (remote_debugging)
  324.     remote_resume (step, 0);
  325.   else {
  326. #ifdef NO_SINGLE_STEP
  327.     if (step) {
  328.       single_step(sig);    /* Do it the hard way, w/temp breakpoints */
  329.       step = 0;        /* ...and don't ask hardware to do it.  */
  330.     }
  331. #endif
  332.     
  333.     /* Handle any optimized stores to the inferior NOW...  */
  334. #ifdef DO_DEFERRED_STORES
  335.     DO_DEFERRED_STORES;
  336. #endif
  337.     
  338.     target_resume (step, sig);
  339. /*    discard_cleanups (old_cleanups);*/
  340.   }
  341. }
  342.  
  343.  
  344. /* Clear out all variables saying what to do when inferior is continued.
  345.    First do this, then set the ones you want, then call `proceed'.  */
  346.  
  347. void
  348. clear_proceed_status ()
  349. {
  350.   trap_expected = 0;
  351.   step_range_start = 0;
  352.   step_range_end = 0;
  353.   step_frame_address = 0;
  354.   step_over_calls = -1;
  355.   step_resume_break_address = 0;
  356.   stop_after_trap = 0;
  357.   stop_soon_quietly = 0;
  358.   proceed_to_finish = 0;
  359.   breakpoint_proceeded = 1;    /* We're about to proceed... */
  360.  
  361.   /* Discard any remaining commands or status from previous stop.  */
  362.   bpstat_clear (&stop_bpstat);
  363. }
  364.  
  365. /* Basic routine for continuing the program in various fashions.
  366.  
  367.    ADDR is the address to resume at, or -1 for resume where stopped.
  368.    SIGGNAL is the signal to give it, or 0 for none,
  369.      or -1 for act according to how it stopped.
  370.    STEP is nonzero if should trap after one instruction.
  371.      -1 means return after that and print nothing.
  372.      You should probably set various step_... variables
  373.      before calling here, if you are stepping.
  374.  
  375.    You should call clear_proceed_status before calling proceed.  */
  376.  
  377. void
  378. proceed (addr, siggnal, step)
  379.      CORE_ADDR addr;
  380.      int siggnal;
  381.      int step;
  382. {
  383.   int oneproc = 0;
  384.  
  385.   if (step > 0)
  386.     step_start_function = find_pc_function (read_pc ());
  387.   if (step < 0)
  388.     stop_after_trap = 1;
  389.  
  390.   if (addr == (CORE_ADDR)-1)
  391.     {
  392.       /* If there is a breakpoint at the address we will resume at,
  393.      step one instruction before inserting breakpoints
  394.      so that we do not stop right away.  */
  395.  
  396.       if (!pc_changed && breakpoint_here_p (read_pc ()))
  397.     oneproc = 1;
  398.     }
  399.   else
  400.     {
  401.       write_register (PC_REGNUM, addr);
  402. #ifdef NPC_REGNUM
  403.       write_register (NPC_REGNUM, addr + 4);
  404. #ifdef NNPC_REGNUM
  405.       write_register (NNPC_REGNUM, addr + 8);
  406. #endif
  407. #endif
  408.     }
  409.  
  410.   if (trap_expected_after_continue)
  411.     {
  412.       /* If (step == 0), a trap will be automatically generated after
  413.      the first instruction is executed.  Force step one
  414.      instruction to clear this condition.  This should not occur
  415.      if step is nonzero, but it is harmless in that case.  */
  416.       oneproc = 1;
  417.       trap_expected_after_continue = 0;
  418.     }
  419.  
  420.   if (oneproc)
  421.     /* We will get a trace trap after one instruction.
  422.        Continue it automatically and insert breakpoints then.  */
  423.     trap_expected = 1;
  424.   else
  425.     {
  426.       int temp = insert_breakpoints ();
  427.       if (temp)
  428.     {
  429.       print_sys_errmsg ("ptrace", temp);
  430.       error ("Cannot insert breakpoints.\n\
  431. The same program may be running in another process.");
  432.     }
  433.       breakpoints_inserted = 1;
  434.     }
  435.  
  436.   /* Install inferior's terminal modes.  */
  437.   target_terminal_inferior ();
  438.  
  439.   if (siggnal >= 0)
  440.     stop_signal = siggnal;
  441.   /* If this signal should not be seen by program,
  442.      give it zero.  Used for debugging signals.  */
  443.   else if (stop_signal < NSIG && !signal_program[stop_signal])
  444.     stop_signal= 0;
  445.  
  446.   /* Resume inferior.  */
  447.   resume (oneproc || step || bpstat_should_step (), stop_signal);
  448.  
  449.   /* Wait for it to stop (if not standalone)
  450.      and in any case decode why it stopped, and act accordingly.  */
  451.  
  452.   wait_for_inferior ();
  453.   normal_stop ();
  454. }
  455.  
  456. /* Record the pc and sp of the program the last time it stopped.
  457.    These are just used internally by wait_for_inferior, but need
  458.    to be preserved over calls to it and cleared when the inferior
  459.    is started.  */
  460. static CORE_ADDR prev_pc;
  461. static CORE_ADDR prev_sp;
  462. static CORE_ADDR prev_func_start;
  463. static char *prev_func_name;
  464.  
  465.  
  466. /* Start an inferior Unix child process and sets inferior_pid to its pid.
  467.    EXEC_FILE is the file to run.
  468.    ALLARGS is a string containing the arguments to the program.
  469.    ENV is the environment vector to pass.  Errors reported with error().  */
  470.  
  471. #ifndef SHELL_FILE
  472. #define SHELL_FILE "/bin/sh"
  473. #endif
  474.  
  475. void
  476. child_create_inferior (exec_file, allargs, env)
  477.      char *exec_file;
  478.      char *allargs;
  479.      char **env;
  480. {
  481.   int pid;
  482.   char *shell_command;
  483.   char *shell_file;
  484.   static char default_shell_file[] = SHELL_FILE;
  485.   int len;
  486.   int pending_execs;
  487.   /* Set debug_fork then attach to the child while it sleeps, to debug. */
  488.   static int debug_fork = 0;
  489.   /* This is set to the result of setpgrp, which if vforked, will be visible
  490.      to you in the parent process.  It's only used by humans for debugging.  */
  491.   static int debug_setpgrp = 657473;
  492.   char **save_our_env;
  493.  
  494.   /* The user might want tilde-expansion, and in general probably wants
  495.      the program to behave the same way as if run from
  496.      his/her favorite shell.  So we let the shell run it for us.
  497.      FIXME, this should probably search the local environment (as
  498.      modified by the setenv command), not the env gdb inherited.  */
  499. #ifdef sprite
  500.   shell_file = "/sprite/cmds/sh";
  501. #else /* sprite */
  502.   shell_file = getenv ("SHELL");
  503. #endif
  504.   if (shell_file == NULL)
  505.     shell_file = default_shell_file;
  506.   
  507.   len = 5 + strlen (exec_file) + 1 + strlen (allargs) + 1 + /*slop*/ 10;
  508.   /* If desired, concat something onto the front of ALLARGS.
  509.      SHELL_COMMAND is the result.  */
  510. #ifdef SHELL_COMMAND_CONCAT
  511.   shell_command = (char *) alloca (strlen (SHELL_COMMAND_CONCAT) + len);
  512.   strcpy (shell_command, SHELL_COMMAND_CONCAT);
  513. #else
  514.   shell_command = (char *) alloca (len);
  515.   shell_command[0] = '\0';
  516. #endif
  517.   strcat (shell_command, "exec ");
  518. #ifdef sprite
  519.   strcat (shell_command, "debug ");
  520. #endif
  521.   strcat (shell_command, exec_file);
  522.   strcat (shell_command, " ");
  523.   strcat (shell_command, allargs);
  524.  
  525.   /* exec is said to fail if the executable is open.  */
  526.   close_exec_file ();
  527.  
  528.   /* Retain a copy of our environment variables, since the child will
  529.      replace the value of  environ  and if we're vforked, we have to 
  530.      restore it.  */
  531.   save_our_env = environ;
  532.  
  533.   /* Tell the terminal handling subsystem what tty we plan to run on;
  534.      it will just record the information for later.  */
  535.  
  536.   new_tty_prefork (inferior_io_terminal);
  537.  
  538.   /* It is generally good practice to flush any possible pending stdio
  539.      output prior to doing a fork, to avoid the possibility of both the
  540.      parent and child flushing the same data after the fork. */
  541.  
  542.   fflush (stdout);
  543.   fflush (stderr);
  544.  
  545. #ifdef sprite
  546.   pid = fork();
  547. #else
  548. #if defined(USG) && !defined(HAVE_VFORK)
  549.   pid = fork ();
  550. #else
  551.   if (debug_fork)
  552.     pid = fork ();
  553.   else
  554.     pid = vfork ();
  555. #endif
  556. #endif
  557.  
  558.   if (pid < 0)
  559.     perror_with_name ("vfork");
  560.  
  561.   if (pid == 0)
  562.     {
  563.       if (debug_fork) 
  564.     sleep (debug_fork);
  565.  
  566. #ifdef TIOCGPGRP
  567.       /* Run inferior in a separate process group.  */
  568. #ifdef NEED_POSIX_SETPGID
  569.       debug_setpgrp = setpgid (0, 0);
  570. #else
  571. #if defined(USG) && !defined(SETPGRP_ARGS)
  572.       debug_setpgrp = setpgrp ();
  573. #else
  574.       debug_setpgrp = setpgrp (getpid (), getpid ());
  575. #endif /* USG */
  576. #endif /* NEED_POSIX_SETPGID */
  577.       if (debug_setpgrp == -1)
  578.      perror("setpgrp failed in child");
  579. #endif /* TIOCGPGRP */
  580.  
  581. #ifdef SET_STACK_LIMIT_HUGE
  582.       /* Reset the stack limit back to what it was.  */
  583.       {
  584.     struct rlimit rlim;
  585.  
  586.     getrlimit (RLIMIT_STACK, &rlim);
  587.     rlim.rlim_cur = original_stack_limit;
  588.     setrlimit (RLIMIT_STACK, &rlim);
  589.       }
  590. #endif /* SET_STACK_LIMIT_HUGE */
  591.  
  592.       /* Ask the tty subsystem to switch to the one we specified earlier
  593.      (or to share the current terminal, if none was specified).  */
  594.  
  595.       new_tty ();
  596.  
  597.       /* Changing the signal handlers for the inferior after
  598.      a vfork can also change them for the superior, so we don't mess
  599.      with signals here.  See comments in
  600.      initialize_signals for how we get the right signal handlers
  601.      for the inferior.  */
  602.  
  603. #ifdef sprite
  604.       /*
  605.        * This appears to be needed on Sprite.
  606.        */
  607.       signal (SIGQUIT, SIG_DFL);
  608.       signal (SIGINT, SIG_DFL);
  609. #endif
  610.  
  611. #ifdef USE_PROC_FS
  612.       proc_set_exec_trap ();        /* Use SVR4 /proc interface */
  613. #else
  614.       call_ptrace (0, 0, 0, 0);        /* "Trace me, Dr. Memory!" */
  615. #endif
  616.  
  617.       /* There is no execlpe call, so we have to set the environment
  618.      for our child in the global variable.  If we've vforked, this
  619.      clobbers the parent, but environ is restored a few lines down
  620.      in the parent.  By the way, yes we do need to look down the
  621.      path to find $SHELL.  Rich Pixley says so, and I agree.  */
  622.       environ = env;
  623.       execlp (shell_file, shell_file, "-c", shell_command, (char *)0);
  624.       fprintf (stderr, "Cannot exec %s: %s.\n", shell_file,
  625.            errno < sys_nerr ? sys_errlist[errno] : "unknown error");
  626.       fflush (stderr);
  627.       _exit (0177);
  628.     }
  629.  
  630.   /* Restore our environment in case a vforked child clob'd it.  */
  631.   environ = save_our_env;
  632.  
  633.   /* Now that we have a child process, make it our target.  */
  634.   push_target (&child_ops);
  635.  
  636. #ifdef CREATE_INFERIOR_HOOK
  637.   CREATE_INFERIOR_HOOK (pid);
  638. #endif  
  639.  
  640. /* The process was started by the fork that created it,
  641.    but it will have stopped one instruction after execing the shell.
  642.    Here we must get it up to actual execution of the real program.  */
  643.  
  644.   inferior_pid = pid;        /* Needed for wait_for_inferior stuff below */
  645.  
  646.   clear_proceed_status ();
  647.  
  648.   /* We will get a trace trap after one instruction.
  649.      Continue it automatically.  Eventually (after shell does an exec)
  650.      it will get another trace trap.  Then insert breakpoints and continue.  */
  651.  
  652. #ifdef START_INFERIOR_TRAPS_EXPECTED
  653.   pending_execs = START_INFERIOR_TRAPS_EXPECTED;
  654. #else
  655.   pending_execs = 2;
  656. #endif
  657.  
  658.   init_wait_for_inferior ();
  659.  
  660.   /* Set up the "saved terminal modes" of the inferior
  661.      based on what modes we are starting it with.  */
  662.   target_terminal_init ();
  663.  
  664.   /* Install inferior's terminal modes.  */
  665.   target_terminal_inferior ();
  666.  
  667.   while (1)
  668.     {
  669.       stop_soon_quietly = 1;    /* Make wait_for_inferior be quiet */
  670.       wait_for_inferior ();
  671.       if (stop_signal != SIGTRAP)
  672.     {
  673.       /* Let shell child handle its own signals in its own way */
  674.       /* FIXME, what if child has exit()ed?  Must exit loop somehow */
  675.       resume (0, stop_signal);
  676.     }
  677.       else
  678.     {
  679.       /* We handle SIGTRAP, however; it means child did an exec.  */
  680.       if (0 == --pending_execs)
  681.         break;
  682.       resume (0, 0);        /* Just make it go on */
  683.     }
  684.     }
  685.   stop_soon_quietly = 0;
  686.  
  687.   /* We are now in the child process of interest, having exec'd the
  688.      correct program, and are poised at the first instruction of the
  689.      new program.  */
  690. #ifdef SOLIB_CREATE_INFERIOR_HOOK
  691.   SOLIB_CREATE_INFERIOR_HOOK (pid);
  692. #endif
  693.  
  694.   /* Should this perhaps just be a "proceed" call?  FIXME */
  695.   insert_step_breakpoint ();
  696.   breakpoints_failed = insert_breakpoints ();
  697.   if (!breakpoints_failed)
  698.     {
  699.       breakpoints_inserted = 1;
  700.       target_terminal_inferior();
  701.       /* Start the child program going on its first instruction, single-
  702.      stepping if we need to.  */
  703.       resume (bpstat_should_step (), 0);
  704.       wait_for_inferior ();
  705.       normal_stop ();
  706.     }
  707. }
  708.  
  709. /* Start remote-debugging of a machine over a serial link.  */
  710.  
  711. void
  712. start_remote ()
  713. {
  714.   init_wait_for_inferior ();
  715.   clear_proceed_status ();
  716.   stop_soon_quietly = 1;
  717.   inferior_pid = 3;
  718.   trap_expected = 0;
  719.   wait_for_inferior ();
  720.   normal_stop ();
  721. }
  722.  
  723. /* Initialize static vars when a new inferior begins.  */
  724.  
  725. void
  726. init_wait_for_inferior ()
  727. {
  728.   /* These are meaningless until the first time through wait_for_inferior.  */
  729.   prev_pc = 0;
  730.   prev_sp = 0;
  731.   prev_func_start = 0;
  732.   prev_func_name = NULL;
  733.  
  734.   trap_expected_after_continue = 0;
  735.   breakpoints_inserted = 0;
  736.   mark_breakpoints_out ();
  737.   stop_signal = 0;        /* Don't confuse first call to proceed(). */
  738. }
  739.  
  740.  
  741. /* Attach to process PID, then initialize for debugging it
  742.    and wait for the trace-trap that results from attaching.  */
  743.  
  744. void
  745. child_attach (args, from_tty)
  746.      char *args;
  747.      int from_tty;
  748. {
  749.   char *exec_file;
  750.   int pid;
  751.  
  752.   dont_repeat();
  753.  
  754.   if (!args)
  755.     error_no_arg ("process-id to attach");
  756.  
  757. #ifndef ATTACH_DETACH
  758.   error ("Can't attach to a process on this machine.");
  759. #else
  760. #ifdef sprite
  761.   /*
  762.    * Since Sprite pids are displayed in hex the atoi doesn't work. We
  763.    * allow the attach command to use any C expression.
  764.    */
  765.   pid = value_as_long (evaluate_expression (parse_expression (args)));
  766. #else
  767.   pid = atoi (args);
  768. #endif /* Sprite */
  769.   if (target_has_execution)
  770.     {
  771.       if (query ("A program is being debugged already.  Kill it? "))
  772.     target_kill ();
  773.       else
  774.     error ("Inferior not killed.");
  775.     }
  776.  
  777.   exec_file = (char *) get_exec_file (1);
  778.  
  779.   if (from_tty)
  780.     {
  781.       printf ("Attaching program: %s pid %d\n",
  782.           exec_file, pid);
  783.       fflush (stdout);
  784.     }
  785.  
  786.   attach (pid);
  787.   inferior_pid = pid;
  788.   push_target (&child_ops);
  789.  
  790.   mark_breakpoints_out ();
  791.   target_terminal_init ();
  792.   clear_proceed_status ();
  793.   stop_soon_quietly = 1;
  794.   /*proceed (-1, 0, -2);*/
  795.   target_terminal_inferior ();
  796.   wait_for_inferior ();
  797. #ifdef SOLIB_ADD
  798.   SOLIB_ADD ((char *)0, from_tty, (struct target_ops *)0);
  799. #endif
  800.   normal_stop ();
  801. #endif  /* ATTACH_DETACH */
  802. }
  803.  
  804. /* Wait for control to return from inferior to debugger.
  805.    If inferior gets a signal, we may decide to start it up again
  806.    instead of returning.  That is why there is a loop in this function.
  807.    When this function actually returns it means the inferior
  808.    should be left stopped and GDB should read more commands.  */
  809.  
  810. void
  811. wait_for_inferior ()
  812. {
  813.   WAITTYPE w;
  814.   int another_trap;
  815.   int random_signal;
  816.   CORE_ADDR stop_sp;
  817.   CORE_ADDR stop_func_start;
  818.   char *stop_func_name;
  819.   CORE_ADDR prologue_pc, tmp;
  820.   int stop_step_resume_break;
  821.   struct symtab_and_line sal;
  822.   int remove_breakpoints_on_following_step = 0;
  823.   int current_line;
  824.   int handling_longjmp = 0;    /* FIXME */
  825.  
  826.   sal = find_pc_line(prev_pc, 0);
  827.   current_line = sal.line;
  828.  
  829.   while (1)
  830.     {
  831.       /* Clean up saved state that will become invalid.  */
  832.       pc_changed = 0;
  833.       flush_cached_frames ();
  834.       registers_changed ();
  835.  
  836.       target_wait (&w);
  837.  
  838. #ifdef SIGTRAP_STOP_AFTER_LOAD
  839.  
  840.       /* Somebody called load(2), and it gave us a "trap signal after load".
  841.          Ignore it gracefully. */
  842.  
  843.       SIGTRAP_STOP_AFTER_LOAD (w);
  844. #endif
  845.  
  846.       /* See if the process still exists; clean up if it doesn't.  */
  847.       if (WIFEXITED (w))
  848.     {
  849.       target_terminal_ours ();    /* Must do this before mourn anyway */
  850.       if (WEXITSTATUS (w))
  851.         printf ("\nProgram exited with code 0%o.\n", 
  852.              (unsigned int)WEXITSTATUS (w));
  853.       else
  854.         if (!batch_mode())
  855.           printf ("\nProgram exited normally.\n");
  856.       fflush (stdout);
  857.       target_mourn_inferior ();
  858. #ifdef NO_SINGLE_STEP
  859.       one_stepped = 0;
  860. #endif
  861.       stop_print_frame = 0;
  862.       break;
  863.     }
  864.       else if (!WIFSTOPPED (w))
  865.     {
  866.       stop_print_frame = 0;
  867.       stop_signal = WTERMSIG (w);
  868.       target_terminal_ours ();    /* Must do this before mourn anyway */
  869.       target_kill ();        /* kill mourns as well */
  870. #ifdef PRINT_RANDOM_SIGNAL
  871.       printf ("\nProgram terminated: ");
  872.       PRINT_RANDOM_SIGNAL (stop_signal);
  873. #else
  874.       printf ("\nProgram terminated with signal %d, %s\n",
  875.           stop_signal,
  876.           stop_signal < NSIG
  877.           ? sys_siglist[stop_signal]
  878.           : "(undocumented)");
  879. #endif
  880.       printf ("The inferior process no longer exists.\n");
  881.       fflush (stdout);
  882. #ifdef NO_SINGLE_STEP
  883.       one_stepped = 0;
  884. #endif
  885.       break;
  886.     }
  887.       
  888. #ifdef NO_SINGLE_STEP
  889.       if (one_stepped)
  890.     single_step (0);    /* This actually cleans up the ss */
  891. #endif /* NO_SINGLE_STEP */
  892.       
  893.       stop_pc = read_pc ();
  894.       set_current_frame ( create_new_frame (read_register (FP_REGNUM),
  895.                         read_pc ()));
  896.       
  897.       stop_frame_address = FRAME_FP (get_current_frame ());
  898.       stop_sp = read_register (SP_REGNUM);
  899.       stop_func_start = 0;
  900.       stop_func_name = 0;
  901.       /* Don't care about return value; stop_func_start and stop_func_name
  902.      will both be 0 if it doesn't work.  */
  903.       (void) find_pc_partial_function (stop_pc, &stop_func_name,
  904.                        &stop_func_start);
  905.       stop_func_start += FUNCTION_START_OFFSET;
  906.       another_trap = 0;
  907.       bpstat_clear (&stop_bpstat);
  908.       stop_step = 0;
  909.       stop_stack_dummy = 0;
  910.       stop_print_frame = 1;
  911.       stop_step_resume_break = 0;
  912.       random_signal = 0;
  913.       stopped_by_random_signal = 0;
  914.       breakpoints_failed = 0;
  915.       
  916.       /* Look at the cause of the stop, and decide what to do.
  917.      The alternatives are:
  918.      1) break; to really stop and return to the debugger,
  919.      2) drop through to start up again
  920.      (set another_trap to 1 to single step once)
  921.      3) set random_signal to 1, and the decision between 1 and 2
  922.      will be made according to the signal handling tables.  */
  923.       
  924.       stop_signal = WSTOPSIG (w);
  925.       
  926.       /* First, distinguish signals caused by the debugger from signals
  927.      that have to do with the program's own actions.
  928.      Note that breakpoint insns may cause SIGTRAP or SIGILL
  929.      or SIGEMT, depending on the operating system version.
  930.      Here we detect when a SIGILL or SIGEMT is really a breakpoint
  931.      and change it to SIGTRAP.  */
  932.       
  933.       if (stop_signal == SIGTRAP
  934.       || (breakpoints_inserted &&
  935.           (stop_signal == SIGILL
  936.            || stop_signal == SIGEMT))
  937.       || stop_soon_quietly)
  938.     {
  939.       if (stop_signal == SIGTRAP && stop_after_trap)
  940.         {
  941.           stop_print_frame = 0;
  942.           break;
  943.         }
  944.       if (stop_soon_quietly)
  945.         break;
  946.  
  947.       /* Don't even think about breakpoints
  948.          if just proceeded over a breakpoint.
  949.  
  950.          However, if we are trying to proceed over a breakpoint
  951.          and end up in sigtramp, then step_resume_break_address
  952.          will be set and we should check whether we've hit the
  953.          step breakpoint.  */
  954.       if (stop_signal == SIGTRAP && trap_expected
  955.           && step_resume_break_address == 0)
  956.         bpstat_clear (&stop_bpstat);
  957.       else
  958.         {
  959.           /* See if there is a breakpoint at the current PC.  */
  960. #if DECR_PC_AFTER_BREAK
  961.           /* Notice the case of stepping through a jump
  962.          that lands just after a breakpoint.
  963.          Don't confuse that with hitting the breakpoint.
  964.          What we check for is that 1) stepping is going on
  965.          and 2) the pc before the last insn does not match
  966.          the address of the breakpoint before the current pc.  */
  967.           if (prev_pc == stop_pc - DECR_PC_AFTER_BREAK
  968.           || !step_range_end
  969.           || step_resume_break_address
  970.           || handling_longjmp /* FIXME */)
  971. #endif /* DECR_PC_AFTER_BREAK not zero */
  972.         {
  973.           /* See if we stopped at the special breakpoint for
  974.              stepping over a subroutine call.  If both are zero,
  975.              this wasn't the reason for the stop.  */
  976.           if (step_resume_break_address
  977.               && stop_pc - DECR_PC_AFTER_BREAK
  978.                  == step_resume_break_address)
  979.             {
  980.               stop_step_resume_break = 1;
  981.               if (DECR_PC_AFTER_BREAK)
  982.             {
  983.               stop_pc -= DECR_PC_AFTER_BREAK;
  984.               write_register (PC_REGNUM, stop_pc);
  985.               pc_changed = 0;
  986.             }
  987.             }
  988.           else
  989.             {
  990.               stop_bpstat =
  991.             bpstat_stop_status (&stop_pc, stop_frame_address);
  992.               /* Following in case break condition called a
  993.              function.  */
  994.               stop_print_frame = 1;
  995.             }
  996.         }
  997.         }
  998.       
  999.       if (stop_signal == SIGTRAP)
  1000.         random_signal
  1001.           = !(bpstat_explains_signal (stop_bpstat)
  1002.           || trap_expected
  1003.           || stop_step_resume_break
  1004.           || PC_IN_CALL_DUMMY (stop_pc, stop_sp, stop_frame_address)
  1005.           || (step_range_end && !step_resume_break_address));
  1006.       else
  1007.         {
  1008.           random_signal
  1009.         = !(bpstat_explains_signal (stop_bpstat)
  1010.             || stop_step_resume_break
  1011.             /* End of a stack dummy.  Some systems (e.g. Sony
  1012.                news) give another signal besides SIGTRAP,
  1013.                so check here as well as above.  */
  1014.             || PC_IN_CALL_DUMMY (stop_pc, stop_sp, stop_frame_address)
  1015.             );
  1016.           if (!random_signal)
  1017.         stop_signal = SIGTRAP;
  1018.         }
  1019.     }
  1020.       else
  1021.     random_signal = 1;
  1022.       
  1023.       /* For the program's own signals, act according to
  1024.      the signal handling tables.  */
  1025.  
  1026.       if (random_signal)
  1027.     {
  1028.       /* Signal not for debugging purposes.  */
  1029.       int printed = 0;
  1030.       
  1031.       stopped_by_random_signal = 1;
  1032.       
  1033.       if (stop_signal >= NSIG
  1034.           || signal_print[stop_signal])
  1035.         {
  1036.           printed = 1;
  1037.           target_terminal_ours_for_output ();
  1038. #ifdef PRINT_RANDOM_SIGNAL
  1039.           PRINT_RANDOM_SIGNAL (stop_signal);
  1040. #else
  1041.           printf ("\nProgram received signal %d, %s\n",
  1042.               stop_signal,
  1043.               stop_signal < NSIG
  1044.               ? sys_siglist[stop_signal]
  1045.               : "(undocumented)");
  1046. #endif /* PRINT_RANDOM_SIGNAL */
  1047.           fflush (stdout);
  1048.         }
  1049.       if (stop_signal >= NSIG
  1050.           || signal_stop[stop_signal])
  1051.         break;
  1052.       /* If not going to stop, give terminal back
  1053.          if we took it away.  */
  1054.       else if (printed)
  1055.         target_terminal_inferior ();
  1056.  
  1057.       /* Note that virtually all the code below does `if !random_signal'.
  1058.          Perhaps this code should end with a goto or continue.  At least
  1059.          one (now fixed) bug was caused by this -- a !random_signal was
  1060.          missing in one of the tests below.  */
  1061.     }
  1062.  
  1063.       /* Handle cases caused by hitting a breakpoint.  */
  1064.  
  1065.       if (!random_signal)
  1066.     if (bpstat_explains_signal (stop_bpstat))
  1067.       {
  1068.         CORE_ADDR jmp_buf_pc;
  1069.  
  1070.         switch (stop_bpstat->breakpoint_at->type) /* FIXME */
  1071.           {
  1072.         /* If we hit the breakpoint at longjmp, disable it for the
  1073.            duration of this command.  Then, install a temporary
  1074.            breakpoint at the target of the jmp_buf. */
  1075.           case bp_longjmp:
  1076.         disable_longjmp_breakpoint();
  1077.         remove_breakpoints ();
  1078.         breakpoints_inserted = 0;
  1079.         if (!GET_LONGJMP_TARGET(&jmp_buf_pc)) goto keep_going;
  1080.  
  1081.         /* Need to blow away step-resume breakpoint, as it
  1082.            interferes with us */
  1083.         remove_step_breakpoint ();
  1084.         step_resume_break_address = 0;
  1085.         stop_step_resume_break = 0;
  1086.  
  1087. #if 0                /* FIXME - Need to implement nested temporary breakpoints */
  1088.         if (step_over_calls > 0)
  1089.           set_longjmp_resume_breakpoint(jmp_buf_pc,
  1090.                         get_current_frame());
  1091.         else
  1092. #endif                /* 0 */
  1093.           set_longjmp_resume_breakpoint(jmp_buf_pc, NULL);
  1094.         handling_longjmp = 1; /* FIXME */
  1095.         goto keep_going;
  1096.  
  1097.           case bp_longjmp_resume:
  1098.         remove_breakpoints ();
  1099.         breakpoints_inserted = 0;
  1100. #if 0                /* FIXME - Need to implement nested temporary breakpoints */
  1101.         if (step_over_calls
  1102.             && (stop_frame_address
  1103.             INNER_THAN step_frame_address))
  1104.           {
  1105.             another_trap = 1;
  1106.             goto keep_going;
  1107.           }
  1108. #endif                /* 0 */
  1109.         disable_longjmp_breakpoint();
  1110.         handling_longjmp = 0; /* FIXME */
  1111.         break;
  1112.  
  1113.           default:
  1114.         fprintf(stderr, "Unknown breakpoint type %d\n",
  1115.             stop_bpstat->breakpoint_at->type);
  1116.           case bp_watchpoint:
  1117.           case bp_breakpoint:
  1118.           case bp_until:
  1119.           case bp_finish:
  1120.         /* Does a breakpoint want us to stop?  */
  1121.         if (bpstat_stop (stop_bpstat))
  1122.           {
  1123.             stop_print_frame = bpstat_should_print (stop_bpstat);
  1124.             goto stop_stepping;
  1125.           }
  1126.         /* Otherwise, must remove breakpoints and single-step
  1127.            to get us past the one we hit.  */
  1128.         else
  1129.           {
  1130.             remove_breakpoints ();
  1131.             remove_step_breakpoint ();
  1132.             breakpoints_inserted = 0;
  1133.             another_trap = 1;
  1134.           }
  1135.         break;
  1136.           }
  1137.       }
  1138.     else if (stop_step_resume_break)
  1139.       {
  1140.         /* But if we have hit the step-resumption breakpoint,
  1141.            remove it.  It has done its job getting us here.
  1142.            The sp test is to make sure that we don't get hung
  1143.            up in recursive calls in functions without frame
  1144.            pointers.  If the stack pointer isn't outside of
  1145.            where the breakpoint was set (within a routine to be
  1146.            stepped over), we're in the middle of a recursive
  1147.            call. Not true for reg window machines (sparc)
  1148.            because the must change frames to call things and
  1149.            the stack pointer doesn't have to change if it
  1150.            the bp was set in a routine without a frame (pc can
  1151.            be stored in some other window).
  1152.            
  1153.            The removal of the sp test is to allow calls to
  1154.            alloca.  Nasty things were happening.  Oh, well,
  1155.            gdb can only handle one level deep of lack of
  1156.            frame pointer. */
  1157.  
  1158.         /*
  1159.           Disable test for step_frame_address match so that we always stop even if the
  1160.           frames don't match.  Reason: if we hit the step_resume_breakpoint, there is
  1161.           no way to temporarily disable it so that we can step past it.  If we leave
  1162.           the breakpoint in, then we loop forever repeatedly hitting, but never
  1163.           getting past the breakpoint.  This change keeps nexting over recursive
  1164.           function calls from hanging gdb.
  1165.           */
  1166. #if 0
  1167.         if (* step_frame_address == 0
  1168.         || (step_frame_address == stop_frame_address))
  1169. #endif
  1170.           {
  1171.         remove_step_breakpoint ();
  1172.         step_resume_break_address = 0;
  1173.  
  1174.         /* If were waiting for a trap, hitting the step_resume_break
  1175.            doesn't count as getting it.  */
  1176.         if (trap_expected)
  1177.           another_trap = 1;
  1178.           }
  1179.       }
  1180.  
  1181.       /* We come here if we hit a breakpoint but should not
  1182.      stop for it.  Possibly we also were stepping
  1183.      and should stop for that.  So fall through and
  1184.      test for stepping.  But, if not stepping,
  1185.      do not stop.  */
  1186.  
  1187.       /* If this is the breakpoint at the end of a stack dummy,
  1188.      just stop silently.  */
  1189.       if (!random_signal 
  1190.      && PC_IN_CALL_DUMMY (stop_pc, stop_sp, stop_frame_address))
  1191.       {
  1192.         stop_print_frame = 0;
  1193.         stop_stack_dummy = 1;
  1194. #ifdef HP_OS_BUG
  1195.         trap_expected_after_continue = 1;
  1196. #endif
  1197.         break;
  1198.       }
  1199.       
  1200.       if (step_resume_break_address)
  1201.     /* Having a step-resume breakpoint overrides anything
  1202.        else having to do with stepping commands until
  1203.        that breakpoint is reached.  */
  1204.     ;
  1205.       /* If stepping through a line, keep going if still within it.  */
  1206.       else if (!random_signal
  1207.            && step_range_end
  1208.            && stop_pc >= step_range_start
  1209.            && stop_pc < step_range_end
  1210.            /* The step range might include the start of the
  1211.           function, so if we are at the start of the
  1212.           step range and either the stack or frame pointers
  1213.           just changed, we've stepped outside */
  1214.            && !(stop_pc == step_range_start
  1215.             && stop_frame_address
  1216.             && (stop_sp INNER_THAN prev_sp
  1217.             || stop_frame_address != step_frame_address)))
  1218.     {
  1219.       ;
  1220.     }
  1221.       
  1222.       /* We stepped out of the stepping range.  See if that was due
  1223.      to a subroutine call that we should proceed to the end of.  */
  1224.       else if (!random_signal && step_range_end)
  1225.     {
  1226.       if (stop_func_start)
  1227.         {
  1228.           prologue_pc = stop_func_start;
  1229.           SKIP_PROLOGUE (prologue_pc);
  1230.         }
  1231.  
  1232.       /* Did we just take a signal?  */
  1233.       if (IN_SIGTRAMP (stop_pc, stop_func_name)
  1234.           && !IN_SIGTRAMP (prev_pc, prev_func_name))
  1235.         {
  1236.           /* This code is needed at least in the following case:
  1237.          The user types "next" and then a signal arrives (before
  1238.          the "next" is done).  */
  1239.           /* We've just taken a signal; go until we are back to
  1240.          the point where we took it and one more.  */
  1241.           step_resume_break_address = prev_pc;
  1242.           step_resume_break_duplicate =
  1243.         breakpoint_here_p (step_resume_break_address);
  1244.           if (breakpoints_inserted)
  1245.         insert_step_breakpoint ();
  1246.           /* Make sure that the stepping range gets us past
  1247.          that instruction.  */
  1248.           if (step_range_end == 1)
  1249.         step_range_end = (step_range_start = prev_pc) + 1;
  1250.           remove_breakpoints_on_following_step = 1;
  1251.           goto save_pc;
  1252.         }
  1253.  
  1254.       /* ==> See comments at top of file on this algorithm.  <==*/
  1255.       
  1256.       if ((stop_pc == stop_func_start
  1257.            || IN_SOLIB_TRAMPOLINE (stop_pc, stop_func_name))
  1258.           && (stop_func_start != prev_func_start
  1259.           || prologue_pc != stop_func_start
  1260.           || stop_sp != prev_sp))
  1261.         {
  1262.           /* It's a subroutine call.
  1263.          (0)  If we are not stepping over any calls ("stepi"), we
  1264.               just stop.
  1265.          (1)  If we're doing a "next", we want to continue through
  1266.               the call ("step over the call").
  1267.          (2)  If we are in a function-call trampoline (a stub between
  1268.               the calling routine and the real function), locate
  1269.               the real function and change stop_func_start.
  1270.          (3)  If we're doing a "step", and there are no debug symbols
  1271.               at the target of the call, we want to continue through
  1272.               it ("step over the call").
  1273.          (4)  Otherwise, we want to stop soon, after the function
  1274.               prologue ("step into the call"). */
  1275.  
  1276.           if (step_over_calls == 0)
  1277.         {
  1278.           /* I presume that step_over_calls is only 0 when we're
  1279.              supposed to be stepping at the assembly language level. */
  1280.           stop_step = 1;
  1281.           break;
  1282.         }
  1283.  
  1284.           if (step_over_calls > 0)
  1285.         goto step_over_function;
  1286.  
  1287.           tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
  1288.           if (tmp != 0)
  1289.         stop_func_start = tmp;
  1290.  
  1291.           if (find_pc_function (stop_func_start) != 0)
  1292.             goto step_into_function;
  1293.  
  1294. step_over_function:
  1295.           /* A subroutine call has happened.  */
  1296.           /* Set a special breakpoint after the return */
  1297.           step_resume_break_address =
  1298.         ADDR_BITS_REMOVE
  1299.           (SAVED_PC_AFTER_CALL (get_current_frame ()));
  1300.           step_resume_break_duplicate
  1301.         = breakpoint_here_p (step_resume_break_address);
  1302.           if (breakpoints_inserted)
  1303.         insert_step_breakpoint ();
  1304.           goto save_pc;
  1305.  
  1306. step_into_function:
  1307.           /* Subroutine call with source code we should not step over.
  1308.          Do step to the first line of code in it.  */
  1309.           SKIP_PROLOGUE (stop_func_start);
  1310.           sal = find_pc_line (stop_func_start, 0);
  1311.           /* Use the step_resume_break to step until
  1312.          the end of the prologue, even if that involves jumps
  1313.          (as it seems to on the vax under 4.2).  */
  1314.           /* If the prologue ends in the middle of a source line,
  1315.          continue to the end of that source line.
  1316.          Otherwise, just go to end of prologue.  */
  1317. #ifdef PROLOGUE_FIRSTLINE_OVERLAP
  1318.           /* no, don't either.  It skips any code that's
  1319.          legitimately on the first line.  */
  1320. #else
  1321.           if (sal.end && sal.pc != stop_func_start)
  1322.         stop_func_start = sal.end;
  1323. #endif
  1324.  
  1325.           if (stop_func_start == stop_pc)
  1326.         {
  1327.           /* We are already there: stop now.  */
  1328.           stop_step = 1;
  1329.           break;
  1330.         }    
  1331.           else
  1332.         /* Put the step-breakpoint there and go until there. */
  1333.         {
  1334.           step_resume_break_address = stop_func_start;
  1335.           
  1336.           step_resume_break_duplicate
  1337.             = breakpoint_here_p (step_resume_break_address);
  1338.           if (breakpoints_inserted)
  1339.             insert_step_breakpoint ();
  1340.           /* Do not specify what the fp should be when we stop
  1341.              since on some machines the prologue
  1342.              is where the new fp value is established.  */
  1343.           step_frame_address = 0;
  1344.           /* And make sure stepping stops right away then.  */
  1345.           step_range_end = step_range_start;
  1346.         }
  1347.           goto save_pc;
  1348.         }
  1349.  
  1350.       /* We've wandered out of the step range (but haven't done a
  1351.          subroutine call or return).  */
  1352.  
  1353.       sal = find_pc_line(stop_pc, 0);
  1354.       
  1355.       if (step_range_end == 1 ||    /* stepi or nexti */
  1356.           sal.line == 0 ||        /* ...or no line # info */
  1357.           (stop_pc == sal.pc    /* ...or we're at the start */
  1358.            && current_line != sal.line)) {    /* of a different line */
  1359.         /* Stop because we're done stepping.  */
  1360.         stop_step = 1;
  1361.         break;
  1362.       } else {
  1363.         /* We aren't done stepping, and we have line number info for $pc.
  1364.            Optimize by setting the step_range for the line.  
  1365.            (We might not be in the original line, but if we entered a
  1366.            new line in mid-statement, we continue stepping.  This makes 
  1367.            things like for(;;) statements work better.)  */
  1368.         step_range_start = sal.pc;
  1369.         step_range_end = sal.end;
  1370.         goto save_pc;
  1371.       }
  1372.       /* We never fall through here */
  1373.     }
  1374.  
  1375.       if (trap_expected
  1376.       && IN_SIGTRAMP (stop_pc, stop_func_name)
  1377.       && !IN_SIGTRAMP (prev_pc, prev_func_name))
  1378.     {
  1379.       /* What has happened here is that we have just stepped the inferior
  1380.          with a signal (because it is a signal which shouldn't make
  1381.          us stop), thus stepping into sigtramp.
  1382.  
  1383.          So we need to set a step_resume_break_address breakpoint
  1384.          and continue until we hit it, and then step.  */
  1385.       step_resume_break_address = prev_pc;
  1386.       /* Always 1, I think, but it's probably easier to have
  1387.          the step_resume_break as usual rather than trying to
  1388.          re-use the breakpoint which is already there.  */
  1389.       step_resume_break_duplicate =
  1390.         breakpoint_here_p (step_resume_break_address);
  1391.       if (breakpoints_inserted)
  1392.         insert_step_breakpoint ();
  1393.       remove_breakpoints_on_following_step = 1;
  1394.       another_trap = 1;
  1395.     }
  1396.  
  1397. /* My apologies to the gods of structured programming. */
  1398. /* Come to this label when you need to resume the inferior.  It's really much
  1399.    cleaner at this time to do a goto than to try and figure out what the
  1400.    if-else chain ought to look like!! */
  1401.  
  1402.     keep_going:
  1403.  
  1404. save_pc:
  1405.       /* Save the pc before execution, to compare with pc after stop.  */
  1406.       prev_pc = read_pc ();    /* Might have been DECR_AFTER_BREAK */
  1407.       prev_func_start = stop_func_start; /* Ok, since if DECR_PC_AFTER
  1408.                       BREAK is defined, the
  1409.                       original pc would not have
  1410.                       been at the start of a
  1411.                       function. */
  1412.       prev_func_name = stop_func_name;
  1413.       prev_sp = stop_sp;
  1414.  
  1415.       /* If we did not do break;, it means we should keep
  1416.      running the inferior and not return to debugger.  */
  1417.  
  1418.       if (trap_expected && stop_signal != SIGTRAP)
  1419.     {
  1420.       /* We took a signal (which we are supposed to pass through to
  1421.          the inferior, else we'd have done a break above) and we
  1422.          haven't yet gotten our trap.  Simply continue.  */
  1423.       resume ((step_range_end && !step_resume_break_address)
  1424.           || (trap_expected && !step_resume_break_address)
  1425.           || bpstat_should_step (),
  1426.           stop_signal);
  1427.     }
  1428.       else
  1429.     {
  1430.       /* Either the trap was not expected, but we are continuing
  1431.          anyway (the user asked that this signal be passed to the
  1432.          child)
  1433.            -- or --
  1434.          The signal was SIGTRAP, e.g. it was our signal, but we
  1435.          decided we should resume from it.
  1436.  
  1437.          We're going to run this baby now!
  1438.  
  1439.          Insert breakpoints now, unless we are trying
  1440.          to one-proceed past a breakpoint.  */
  1441.       /* If we've just finished a special step resume and we don't
  1442.          want to hit a breakpoint, pull em out.  */
  1443.       if (!step_resume_break_address &&
  1444.           remove_breakpoints_on_following_step)
  1445.         {
  1446.           remove_breakpoints_on_following_step = 0;
  1447.           remove_breakpoints ();
  1448.           breakpoints_inserted = 0;
  1449.         }
  1450.       else if (!breakpoints_inserted &&
  1451.            (step_resume_break_address != 0 || !another_trap))
  1452.         {
  1453.           insert_step_breakpoint ();
  1454.           breakpoints_failed = insert_breakpoints ();
  1455.           if (breakpoints_failed)
  1456.         break;
  1457.           breakpoints_inserted = 1;
  1458.         }
  1459.  
  1460.       trap_expected = another_trap;
  1461.  
  1462.       if (stop_signal == SIGTRAP)
  1463.         stop_signal = 0;
  1464.  
  1465. #ifdef SHIFT_INST_REGS
  1466.       /* I'm not sure when this following segment applies.  I do know, now,
  1467.          that we shouldn't rewrite the regs when we were stopped by a
  1468.          random signal from the inferior process.  */
  1469.  
  1470.           if (!bpstat_explains_signal (stop_bpstat)
  1471.           && (stop_signal != SIGCLD) 
  1472.               && !stopped_by_random_signal)
  1473.             {
  1474.             CORE_ADDR pc_contents = read_register (PC_REGNUM);
  1475.             CORE_ADDR npc_contents = read_register (NPC_REGNUM);
  1476.             if (pc_contents != npc_contents)
  1477.               {
  1478.               write_register (NNPC_REGNUM, npc_contents);
  1479.               write_register (NPC_REGNUM, pc_contents);
  1480.           }
  1481.             }
  1482. #endif /* SHIFT_INST_REGS */
  1483.  
  1484.       resume ((!step_resume_break_address
  1485.            && !handling_longjmp
  1486.            && (step_range_end
  1487.                || trap_expected))
  1488.           || bpstat_should_step (),
  1489.           stop_signal);
  1490.     }
  1491.     }
  1492.  
  1493.  stop_stepping:
  1494.   if (target_has_execution)
  1495.     {
  1496.       /* Assuming the inferior still exists, set these up for next
  1497.      time, just like we did above if we didn't break out of the
  1498.      loop.  */
  1499.       prev_pc = read_pc ();
  1500.       prev_func_start = stop_func_start;
  1501.       prev_func_name = stop_func_name;
  1502.       prev_sp = stop_sp;
  1503.     }
  1504. }
  1505.  
  1506. /* Here to return control to GDB when the inferior stops for real.
  1507.    Print appropriate messages, remove breakpoints, give terminal our modes.
  1508.  
  1509.    STOP_PRINT_FRAME nonzero means print the executing frame
  1510.    (pc, function, args, file, line number and line text).
  1511.    BREAKPOINTS_FAILED nonzero means stop was due to error
  1512.    attempting to insert breakpoints.  */
  1513.  
  1514. void
  1515. normal_stop ()
  1516. {
  1517.   /* Make sure that the current_frame's pc is correct.  This
  1518.      is a correction for setting up the frame info before doing
  1519.      DECR_PC_AFTER_BREAK */
  1520.   if (target_has_execution)
  1521.     (get_current_frame ())->pc = read_pc ();
  1522.   
  1523.   if (breakpoints_failed)
  1524.     {
  1525.       target_terminal_ours_for_output ();
  1526.       print_sys_errmsg ("ptrace", breakpoints_failed);
  1527.       printf ("Stopped; cannot insert breakpoints.\n\
  1528. The same program may be running in another process.\n");
  1529.     }
  1530.  
  1531.   if (target_has_execution)
  1532.     remove_step_breakpoint ();
  1533.  
  1534.   if (target_has_execution && breakpoints_inserted)
  1535.     if (remove_breakpoints ())
  1536.       {
  1537.     target_terminal_ours_for_output ();
  1538.     printf ("Cannot remove breakpoints because program is no longer writable.\n\
  1539. It might be running in another process.\n\
  1540. Further execution is probably impossible.\n");
  1541.       }
  1542.  
  1543.   breakpoints_inserted = 0;
  1544.  
  1545.   /* Delete the breakpoint we stopped at, if it wants to be deleted.
  1546.      Delete any breakpoint that is to be deleted at the next stop.  */
  1547.  
  1548.   breakpoint_auto_delete (stop_bpstat);
  1549.  
  1550.   /* If an auto-display called a function and that got a signal,
  1551.      delete that auto-display to avoid an infinite recursion.  */
  1552.  
  1553.   if (stopped_by_random_signal)
  1554.     disable_current_display ();
  1555.  
  1556.   if (step_multi && stop_step)
  1557.     return;
  1558.  
  1559.   target_terminal_ours ();
  1560.  
  1561.   if (!target_has_stack)
  1562.     return;
  1563.  
  1564.   /* Select innermost stack frame except on return from a stack dummy routine,
  1565.      or if the program has exited.  Print it without a level number if
  1566.      we have changed functions or hit a breakpoint.  Print source line
  1567.      if we have one.  */
  1568.   if (!stop_stack_dummy)
  1569.     {
  1570.       select_frame (get_current_frame (), 0);
  1571.  
  1572.       if (stop_print_frame)
  1573.     {
  1574.       int source_only;
  1575.  
  1576.       source_only = bpstat_print (stop_bpstat);
  1577.       source_only = source_only ||
  1578.             (   stop_step
  1579.          && step_frame_address == stop_frame_address
  1580.          && step_start_function == find_pc_function (stop_pc));
  1581.  
  1582.           print_stack_frame (selected_frame, -1, source_only? -1: 1);
  1583.  
  1584.       /* Display the auto-display expressions.  */
  1585.       do_displays ();
  1586.     }
  1587.     }
  1588.  
  1589.   /* Save the function value return registers, if we care.
  1590.      We might be about to restore their previous contents.  */
  1591.   if (proceed_to_finish)
  1592.     read_register_bytes (0, stop_registers, REGISTER_BYTES);
  1593.  
  1594.   if (stop_stack_dummy)
  1595.     {
  1596.       /* Pop the empty frame that contains the stack dummy.
  1597.          POP_FRAME ends with a setting of the current frame, so we
  1598.      can use that next. */
  1599.       POP_FRAME;
  1600.       select_frame (get_current_frame (), 0);
  1601.     }
  1602. }
  1603.  
  1604. static void
  1605. insert_step_breakpoint ()
  1606. {
  1607.   if (step_resume_break_address && !step_resume_break_duplicate)
  1608.     target_insert_breakpoint (step_resume_break_address,
  1609.                   step_resume_break_shadow);
  1610. }
  1611.  
  1612. static void
  1613. remove_step_breakpoint ()
  1614. {
  1615.   if (step_resume_break_address && !step_resume_break_duplicate)
  1616.     target_remove_breakpoint (step_resume_break_address,
  1617.                   step_resume_break_shadow);
  1618. }
  1619.  
  1620. int signal_stop_state (signo)
  1621.      int signo;
  1622. {
  1623.   return ((signo >= 0 && signo < NSIG) ? signal_stop[signo] : 0);
  1624. }
  1625.  
  1626. int signal_print_state (signo)
  1627.      int signo;
  1628. {
  1629.   return ((signo >= 0 && signo < NSIG) ? signal_print[signo] : 0);
  1630. }
  1631.  
  1632. int signal_pass_state (signo)
  1633.      int signo;
  1634. {
  1635.   return ((signo >= 0 && signo < NSIG) ? signal_program[signo] : 0);
  1636. }
  1637.  
  1638. static void
  1639. sig_print_header ()
  1640. {
  1641.   printf_filtered ("Signal\t\tStop\tPrint\tPass to program\tDescription\n");
  1642. }
  1643.  
  1644. static void
  1645. sig_print_info (number)
  1646.      int number;
  1647. {
  1648.   char *abbrev = sig_abbrev(number);
  1649.   if (abbrev == NULL)
  1650.     printf_filtered ("%d\t\t", number);
  1651.   else
  1652.     printf_filtered ("SIG%s (%d)\t", abbrev, number);
  1653.   printf_filtered ("%s\t", signal_stop[number] ? "Yes" : "No");
  1654.   printf_filtered ("%s\t", signal_print[number] ? "Yes" : "No");
  1655.   printf_filtered ("%s\t\t", signal_program[number] ? "Yes" : "No");
  1656.   printf_filtered ("%s\n", sys_siglist[number]);
  1657. }
  1658.  
  1659. /* Specify how various signals in the inferior should be handled.  */
  1660.  
  1661. static void
  1662. handle_command (args, from_tty)
  1663.      char *args;
  1664.      int from_tty;
  1665. {
  1666.   register char *p = args;
  1667.   int signum = 0;
  1668.   register int digits, wordlen;
  1669.   char *nextarg;
  1670.  
  1671.   if (!args)
  1672.     error_no_arg ("signal to handle");
  1673.  
  1674.   while (*p)
  1675.     {
  1676.       /* Find the end of the next word in the args.  */
  1677.       for (wordlen = 0;
  1678.        p[wordlen] && p[wordlen] != ' ' && p[wordlen] != '\t';
  1679.        wordlen++);
  1680.       /* Set nextarg to the start of the word after the one we just
  1681.      found, and null-terminate this one.  */
  1682.       if (p[wordlen] == '\0')
  1683.     nextarg = p + wordlen;
  1684.       else
  1685.     {
  1686.       p[wordlen] = '\0';
  1687.       nextarg = p + wordlen + 1;
  1688.     }
  1689.       
  1690.  
  1691.       for (digits = 0; p[digits] >= '0' && p[digits] <= '9'; digits++);
  1692.  
  1693.       if (signum == 0)
  1694.     {
  1695.       /* It is the first argument--must be the signal to operate on.  */
  1696.       if (digits == wordlen)
  1697.         {
  1698.           /* Numeric.  */
  1699.           signum = atoi (p);
  1700.           if (signum <= 0 || signum >= NSIG)
  1701.         {
  1702.           p[wordlen] = '\0';
  1703.           error ("Invalid signal %s given as argument to \"handle\".", p);
  1704.         }
  1705.         }
  1706.       else
  1707.         {
  1708.           /* Symbolic.  */
  1709.           signum = sig_number (p);
  1710.           if (signum == -1)
  1711.         error ("No such signal \"%s\"", p);
  1712.         }
  1713.  
  1714.       if (signum == SIGTRAP || signum == SIGINT)
  1715.         {
  1716.           if (!query ("SIG%s is used by the debugger.\nAre you sure you want to change it? ", sig_abbrev (signum)))
  1717.         error ("Not confirmed.");
  1718.         }
  1719.     }
  1720.       /* Else, if already got a signal number, look for flag words
  1721.      saying what to do for it.  */
  1722.       else if (!strncmp (p, "stop", wordlen))
  1723.     {
  1724.       signal_stop[signum] = 1;
  1725.       signal_print[signum] = 1;
  1726.     }
  1727.       else if (wordlen >= 2 && !strncmp (p, "print", wordlen))
  1728.     signal_print[signum] = 1;
  1729.       else if (wordlen >= 2 && !strncmp (p, "pass", wordlen))
  1730.     signal_program[signum] = 1;
  1731.       else if (!strncmp (p, "ignore", wordlen))
  1732.     signal_program[signum] = 0;
  1733.       else if (wordlen >= 3 && !strncmp (p, "nostop", wordlen))
  1734.     signal_stop[signum] = 0;
  1735.       else if (wordlen >= 4 && !strncmp (p, "noprint", wordlen))
  1736.     {
  1737.       signal_print[signum] = 0;
  1738.       signal_stop[signum] = 0;
  1739.     }
  1740.       else if (wordlen >= 4 && !strncmp (p, "nopass", wordlen))
  1741.     signal_program[signum] = 0;
  1742.       else if (wordlen >= 3 && !strncmp (p, "noignore", wordlen))
  1743.     signal_program[signum] = 1;
  1744.       /* Not a number and not a recognized flag word => complain.  */
  1745.       else
  1746.     {
  1747.       error ("Unrecognized or ambiguous flag word: \"%s\".", p);
  1748.     }
  1749.  
  1750.       /* Find start of next word.  */
  1751.       p = nextarg;
  1752.       while (*p == ' ' || *p == '\t') p++;
  1753.     }
  1754.  
  1755.   NOTICE_SIGNAL_HANDLING_CHANGE;
  1756.  
  1757.   if (from_tty)
  1758.     {
  1759.       /* Show the results.  */
  1760.       sig_print_header ();
  1761.       sig_print_info (signum);
  1762.     }
  1763. }
  1764.  
  1765. /* Print current contents of the tables set by the handle command.  */
  1766.  
  1767. static void
  1768. signals_info (signum_exp, from_tty)
  1769.      char *signum_exp;
  1770.      int from_tty;
  1771. {
  1772.   register int i;
  1773.   sig_print_header ();
  1774.  
  1775.   if (signum_exp)
  1776.     {
  1777.       /* First see if this is a symbol name.  */
  1778.       i = sig_number (signum_exp);
  1779.       if (i == -1)
  1780.     {
  1781.       /* Nope, maybe it's an address which evaluates to a signal
  1782.          number.  */
  1783.       i = parse_and_eval_address (signum_exp);
  1784.       if (i >= NSIG || i < 0)
  1785.         error ("Signal number out of bounds.");
  1786.     }
  1787.       sig_print_info (i);
  1788.       return;
  1789.     }
  1790.  
  1791.   printf_filtered ("\n");
  1792.   for (i = 0; i < NSIG; i++)
  1793.     {
  1794.       QUIT;
  1795.  
  1796.       sig_print_info (i);
  1797.     }
  1798.  
  1799.   printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
  1800. }
  1801.  
  1802. /* Save all of the information associated with the inferior<==>gdb
  1803.    connection.  INF_STATUS is a pointer to a "struct inferior_status"
  1804.    (defined in inferior.h).  */
  1805.  
  1806. void
  1807. save_inferior_status (inf_status, restore_stack_info)
  1808.      struct inferior_status *inf_status;
  1809.      int restore_stack_info;
  1810. {
  1811.   inf_status->pc_changed = pc_changed;
  1812.   inf_status->stop_signal = stop_signal;
  1813.   inf_status->stop_pc = stop_pc;
  1814.   inf_status->stop_frame_address = stop_frame_address;
  1815.   inf_status->stop_step = stop_step;
  1816.   inf_status->stop_stack_dummy = stop_stack_dummy;
  1817.   inf_status->stopped_by_random_signal = stopped_by_random_signal;
  1818.   inf_status->trap_expected = trap_expected;
  1819.   inf_status->step_range_start = step_range_start;
  1820.   inf_status->step_range_end = step_range_end;
  1821.   inf_status->step_frame_address = step_frame_address;
  1822.   inf_status->step_over_calls = step_over_calls;
  1823.   inf_status->step_resume_break_address = step_resume_break_address;
  1824.   inf_status->stop_after_trap = stop_after_trap;
  1825.   inf_status->stop_soon_quietly = stop_soon_quietly;
  1826.   /* Save original bpstat chain here; replace it with copy of chain. 
  1827.      If caller's caller is walking the chain, they'll be happier if we
  1828.      hand them back the original chain when restore_i_s is called.  */
  1829.   inf_status->stop_bpstat = stop_bpstat;
  1830.   stop_bpstat = bpstat_copy (stop_bpstat);
  1831.   inf_status->breakpoint_proceeded = breakpoint_proceeded;
  1832.   inf_status->restore_stack_info = restore_stack_info;
  1833.   inf_status->proceed_to_finish = proceed_to_finish;
  1834.   
  1835.   bcopy (stop_registers, inf_status->stop_registers, REGISTER_BYTES);
  1836.   
  1837.   record_selected_frame (&(inf_status->selected_frame_address),
  1838.              &(inf_status->selected_level));
  1839.   return;
  1840. }
  1841.  
  1842. void
  1843. restore_inferior_status (inf_status)
  1844.      struct inferior_status *inf_status;
  1845. {
  1846.   FRAME fid;
  1847.   int level = inf_status->selected_level;
  1848.  
  1849.   pc_changed = inf_status->pc_changed;
  1850.   stop_signal = inf_status->stop_signal;
  1851.   stop_pc = inf_status->stop_pc;
  1852.   stop_frame_address = inf_status->stop_frame_address;
  1853.   stop_step = inf_status->stop_step;
  1854.   stop_stack_dummy = inf_status->stop_stack_dummy;
  1855.   stopped_by_random_signal = inf_status->stopped_by_random_signal;
  1856.   trap_expected = inf_status->trap_expected;
  1857.   step_range_start = inf_status->step_range_start;
  1858.   step_range_end = inf_status->step_range_end;
  1859.   step_frame_address = inf_status->step_frame_address;
  1860.   step_over_calls = inf_status->step_over_calls;
  1861.   step_resume_break_address = inf_status->step_resume_break_address;
  1862.   stop_after_trap = inf_status->stop_after_trap;
  1863.   stop_soon_quietly = inf_status->stop_soon_quietly;
  1864.   bpstat_clear (&stop_bpstat);
  1865.   stop_bpstat = inf_status->stop_bpstat;
  1866.   breakpoint_proceeded = inf_status->breakpoint_proceeded;
  1867.   proceed_to_finish = inf_status->proceed_to_finish;
  1868.  
  1869.   bcopy (inf_status->stop_registers, stop_registers, REGISTER_BYTES);
  1870.  
  1871.   /* The inferior can be gone if the user types "print exit(0)"
  1872.      (and perhaps other times).  */
  1873.   if (target_has_stack && inf_status->restore_stack_info)
  1874.     {
  1875.       fid = find_relative_frame (get_current_frame (),
  1876.                  &level);
  1877.  
  1878.       /* If inf_status->selected_frame_address is NULL, there was no
  1879.      previously selected frame.  */
  1880.       if (fid == 0 ||
  1881.       FRAME_FP (fid) != inf_status->selected_frame_address ||
  1882.       level != 0)
  1883.     {
  1884. #if 1
  1885.       /* I'm not sure this error message is a good idea.  I have
  1886.          only seen it occur after "Can't continue previously
  1887.          requested operation" (we get called from do_cleanups), in
  1888.          which case it just adds insult to injury (one confusing
  1889.          error message after another.  Besides which, does the
  1890.          user really care if we can't restore the previously
  1891.          selected frame?  */
  1892.       fprintf (stderr, "Unable to restore previously selected frame.\n");
  1893. #endif
  1894.       select_frame (get_current_frame (), 0);
  1895.       return;
  1896.     }
  1897.       
  1898.       select_frame (fid, inf_status->selected_level);
  1899.     }
  1900. }
  1901.  
  1902.  
  1903. void
  1904. _initialize_infrun ()
  1905. {
  1906.   register int i;
  1907.  
  1908.   add_info ("signals", signals_info,
  1909.         "What debugger does when program gets various signals.\n\
  1910. Specify a signal number as argument to print info on that signal only.");
  1911.  
  1912.   add_com ("handle", class_run, handle_command,
  1913.        "Specify how to handle a signal.\n\
  1914. Args are signal number followed by flags.\n\
  1915. Flags allowed are \"stop\", \"print\", \"pass\",\n\
  1916.  \"nostop\", \"noprint\" or \"nopass\".\n\
  1917. Print means print a message if this signal happens.\n\
  1918. Stop means reenter debugger if this signal happens (implies print).\n\
  1919. Pass means let program see this signal; otherwise program doesn't know.\n\
  1920. Pass and Stop may be combined.");
  1921.  
  1922.   for (i = 0; i < NSIG; i++)
  1923.     {
  1924.       signal_stop[i] = 1;
  1925.       signal_print[i] = 1;
  1926.       signal_program[i] = 1;
  1927.     }
  1928.  
  1929.   /* Signals caused by debugger's own actions
  1930.      should not be given to the program afterwards.  */
  1931.   signal_program[SIGTRAP] = 0;
  1932.   signal_program[SIGINT] = 0;
  1933.  
  1934.   /* Signals that are not errors should not normally enter the debugger.  */
  1935. #ifdef SIGALRM
  1936.   signal_stop[SIGALRM] = 0;
  1937.   signal_print[SIGALRM] = 0;
  1938. #endif /* SIGALRM */
  1939. #ifdef SIGVTALRM
  1940.   signal_stop[SIGVTALRM] = 0;
  1941.   signal_print[SIGVTALRM] = 0;
  1942. #endif /* SIGVTALRM */
  1943. #ifdef SIGPROF
  1944.   signal_stop[SIGPROF] = 0;
  1945.   signal_print[SIGPROF] = 0;
  1946. #endif /* SIGPROF */
  1947. #ifdef SIGCHLD
  1948.   signal_stop[SIGCHLD] = 0;
  1949.   signal_print[SIGCHLD] = 0;
  1950. #endif /* SIGCHLD */
  1951. #ifdef SIGCLD
  1952.   signal_stop[SIGCLD] = 0;
  1953.   signal_print[SIGCLD] = 0;
  1954. #endif /* SIGCLD */
  1955. #ifdef SIGIO
  1956.   signal_stop[SIGIO] = 0;
  1957.   signal_print[SIGIO] = 0;
  1958. #endif /* SIGIO */
  1959. #ifdef SIGURG
  1960.   signal_stop[SIGURG] = 0;
  1961.   signal_print[SIGURG] = 0;
  1962. #endif /* SIGURG */
  1963. }
  1964.